import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class NewsTab {
  String text;
  String tab;

  NewsTab(this.text, this.tab);
}

//定义tab基本数据结构
final List<NewsTab> newsTabs = <NewsTab>[
  NewsTab('金融', 'financial'),
  NewsTab('科技', 'technology'),
  NewsTab('医疗', 'medical')
];

class TabNavigation extends StatelessWidget {
  final NewsTab currentTab;
  final ValueChanged<NewsTab> onSelectTab;

  const TabNavigation({Key key, this.currentTab, this.onSelectTab})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: newsTabs.map((item) {
        return GestureDetector(
            child: Container(
              padding: const EdgeInsets.fromLTRB(24.0, 0.0, 24.0, 0.0),
              child: Text(item.text,
                  style: TextStyle(color: _colorTabMatching(item: item))),
            ),
            onTap: () => onSelectTab(item));
      }).toList(),
    );
  }

  Color _colorTabMatching({NewsTab item}) {
    return currentTab == item ? Colors.black : Colors.grey;
  }
}
